﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace YXShop.Web.membercenter.shop.shop_administer
{
    public partial class shop_leaveword_edit : System.Web.UI.Page
    {
        YXShop.BLL.Accessories.Leaveword leaveBll = new YXShop.BLL.Accessories.Leaveword();
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                InitWebControl();
                string leaveId = ChangeHope.WebPage.PageRequest.GetQueryString("leaveId");
                if(leaveId!=null&&leaveId!="")
                {
                    ViewState["leaveId"]=leaveId;
                    InitModel(Convert.ToInt32(leaveId));
                }
            }
        }
          #region 验证
        private void InitWebControl()
        {
            ChangeHope.WebPage.WebControl.Validate(this.txtRevert,"回复内容不能为空","isnull","必填","该项为必填项");
            this.Form.Attributes.Add("onsubmit","return CheckForm()");
        }
          #endregion
        private void InitModel(int id)
        {          
            YXShop.Model.Accessories.Leaveword model = leaveBll.GetModelByID(id);
            if(model!=null)
            {
                this.lblTheme.Text = model.Title.ToString();
                this.lblName.Text = model.UserName.ToString();
                this.lblContent.Text = model.Content.ToString();
                this.rblAuditing.SelectedValue = model.IsAuditing.ToString();
                this.txtRevert.Text = model.ReplyContent.ToString();
                if(Convert.ToInt32(model.IsRead)==0)
                {
                    leaveBll.Amend(id, "isread", 1);
                }
                if(Convert.ToInt32(model.IsReply)==1)
                {
                    this.txtRevert.Enabled = false;
                }
               
            }
        }

        private void Restore()
        {
            if (ViewState["leaveId"]!=null)
            {
                YXShop.Model.Accessories.Leaveword model = leaveBll.GetModelByID(Convert.ToInt32(ViewState["leaveId"]));
                model.IsReply = 1;
                model.ReplyContent = this.txtRevert.Text.Trim().ToString();
                model.ReplyDate = Convert.ToDateTime(System.DateTime.Now);
                model.IsAuditing = Convert.ToInt32(this.rblAuditing.SelectedValue);
                try
                {
                    leaveBll.Amend(model);
                    this.ltlMsg.Text = "操作成功，已回复该信息";
                    this.pnlMsg.Visible = true;
                    this.pnlMsg.CssClass = "actionOk";
                }
                catch (Exception e)
                {
                    this.ltlMsg.Text = "操作失败，请联系管理员";
                    this.pnlMsg.Visible = true;
                    this.pnlMsg.CssClass = "actionErr";
                }              
            }
        }

        protected void linkSave_Click(object sender, EventArgs e)
        {
            Restore();
        }
    }
}
